package com.xuecheng.base.config.xc;

import com.xuecheng.base.enums.AcknowledgeModeEnum;
import com.xuecheng.base.enums.ConfirmEnum;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.stereotype.Component;

/**
 * @author 勾新杰
 * @version 1.0
 * @description:
 * @date 2025/3/8 15:46
 */
@Data
@Component
@ConfigurationProperties(prefix = "xuecheng.rabbitmq")
public class XCRabbitMQProperties {

    /**
     * rabbitmq地址
     */
    private String host;

    /**
     * rabbitmq端口
     */
    private Integer port;

    /**
     * rabbitmq用户名
     */
    private String username;

    /**
     * rabbitmq密码
     */
    private String password;

    /**
     * rabbitmq虚拟主机
     */
    private String virtualHost;

    /**
     * 生产者确认
     */
    private ConfirmEnum publisherConfirms;

    /**
     * 生产者回调
     */
    private Boolean publisherReturns;

    /**
     * 消费者配置
     */
    @NestedConfigurationProperty
    private XCRabbitMQListenerProperties listener;

    /**
     * 消费者配置
     */
    @Data
    public static class XCRabbitMQListenerProperties {

        /**
         * 简单消费者配置
         */
        @NestedConfigurationProperty
        private XCRabbitMQListenerSimpleProperties simple;
    }

    /**
     * 消费者配置
     */
    @Data
    public static class XCRabbitMQListenerSimpleProperties {

        /**
         * 消费者确认模式
         */
        private AcknowledgeModeEnum acknowledgeMode;

        /**
         * 消费者预取值
         */
        private Integer prefetch = 10;

        /**
         * 消费者失败重试配置
         */
        @NestedConfigurationProperty
        private XCRabbitMQListenerSimpleRetryProperties retry;
    }

    @Data
    public static class XCRabbitMQListenerSimpleRetryProperties {

        /**
         * 是否开启失败重试
         */
        private Boolean enabled;

        /**
         * 失败重试初始等待时长
         */
        private String initialInterval;

        /**
         * 失败重试倍数
         */
        private Integer multiplier;

        /**
         * 失败重试最大次数
         */
        private Integer maxAttempts;

        /**
         * 是否无状态
         */
        private Boolean stateless;
    }
}
